﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FontAwesome.WPF;
using Koala.Pro.Common;
using Koala.Pro.Models;

namespace Koala.Pro.ViewModels
{
    public partial class FontAwesomeListViewModel : BaseViewModel
    {
        [ObservableProperty]
        private CListItem selectedItem = new CListItem();

        [ObservableProperty]
        private List<CListItem> iconItems = new List<CListItem>();

        [ObservableProperty]
        private List<CListItem> allItems = new List<CListItem>();

        public FontAwesomeListViewModel()
        {
            base.Title = "FontAwesome.WPF的图标";
            foreach (KeyValuePair<string, object> item in EnumHelper.GetMemberKeyValue<FontAwesomeIcon>())
            {
                AllItems.Add(new CListItem(item.Key, item.Value.ToString()));
            }
            ResetData();
        }

        public void ResetData()
        {
            IconItems = AllItems;
        }

        [RelayCommand]
        public void GetAll(string iconName)
        {
            if (!iconName.IsNullOrWhiteSpace())
            {
                IconItems = AllItems.Where((CListItem s) => s.Text.Contains(iconName, StringComparison.OrdinalIgnoreCase)).ToList();
            }
            else
            {
                ResetData();
            }
        }
    }
}
